﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="build/treeview/assets/skins/sam/treeview.css" />
    <script type="text/javascript" src="build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="build/treeview/treeview-min.js"></script>
    <link rel="stylesheet" type="text/css" href="build/treeview/assets/css/folders/tree.css">
    <style type="text/css">
        #treeDiv1 { background: #fff; padding:1em; margin-top:1em; }
    </style>
</head>
<body class="yui-skin-sam">

<div id="treeDiv1"></div>
<div id="treeDiv2"></div>
 
<script type="text/javascript">
    (function () {
        var tree;
        function treeInit() {
            buildRandomTextNodeTree();
            YAHOO.util.Event.on("expand", "click", function (e) {
                YAHOO.log("展开所有树形节点", "info", "example");
                tree.expandAll();
                YAHOO.util.Event.preventDefault(e);
            });
            YAHOO.util.Event.on("collapse", "click", function (e) {
                YAHOO.log("收缩所有树形节点", "info", "example");
                tree.collapseAll();
                YAHOO.util.Event.preventDefault(e);
            });
        }
        function buildRandomTextNodeTree() {
            tree = new YAHOO.widget.TreeView("treeDiv1");
            for (var i = 0; i < Math.floor((Math.random() * 4) + 3); i++) {
                var tmpNode = new YAHOO.widget.TextNode("label-" + i, tree.getRoot(), false);
                buildRandomTextBranch(tmpNode);
            }
            tree.draw();
        }
        function buildRandomTextBranch(node) {
            if (node.depth < 6) {
                for (var i = 0; i < Math.floor(Math.random() * 4); i++) {
                    var tmpNode = new YAHOO.widget.TextNode(node.label + "-" + i, node, false);
                    buildRandomTextBranch(tmpNode);
                }
            }
        }
        YAHOO.util.Event.onDOMReady(treeInit);

    })();
 
</script>

</body>
</html>
